<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\CustomerRep;
use Illuminate\Cache\Repository;
use Illuminate\Http\Request;

class Customer extends Controller
{
    //客户管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new CustomerRep();
    }

    /**
     * 获取客户列表
     * @param Request $request
     */
    public function getCustomerList(Request $request){
        $params = $request->all();
        $data = $this->rep->getCustomerListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加
     * @param Request $request
     */
    public function createCustomer(Request $request){
        $params = $request->all();
        $data = $this->rep->createCustomerRep($params);
        return re($data['code'],$data['data']);
    }

    /**
     * 删除客户
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCustomer(Request $request){
        $params = $request->all();
        $data = $this->rep->delCustomerRep($params);
        return re($data['code']);
    }

    /**
     * 充值
     */
    public function topUp(Request $request){
        $params = $request->all();
        $data = $this->rep->topUpRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取经销商列表
     * @return void
     */
    public function getDealerList(Request $request){
        $params = $request->only(['per_page']);
        $data = $this->rep->getDealerListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加编辑经销商
     * @param Request $request
     */
    public function createDealer(Request $request){
        $params = $request->only([
            'user_id','username','parent_username','usernames','passwords','phones','company_names',
            'id','customer_name','provinces','city','county','customer_address','contact','contact_phone','remark','store_name','balance'
        ]);
        $data = $this->rep->createDealerRep($params);
        return re($data['code'],$data['data']);
    }

}
